<?php
/* 
 * Repository class used to get objects out of the peristence layer
 *
 */
class BusinessRepository {

    /**
     * the repositpry  fetch the object from the database and attache
     *
     * @param <type> $class
     * @param <type> $adapters
     * @param <type> $id
     * @return <object>
     */
    static function getObject($class, $creatorAdapter, $adapters = array(), $id){
        if(!is_array($adapters)){
            $adapters = array($adapters);
        }
        $creator = new $creatorAdapter();
        $object = $creator->getObject($class, $id);
        $creator->getObjectState($object);
        $object->addAdapter($creator);

        foreach($adapters as $name){
            /*
             * we pass the object to the $adapter cause he may
             * need to set some internal variable from the object state
             */
            $adapter = new $name();
            $adapter->getObjectState($object);
            $object->addAdapter($adapter);
        }
        return $object;
    }
}
?>
